package com.simba.server.commands.impl.fetch;

import java.sql.ResultSet;
import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;
import com.simba.server.components.data.MachineRunInfo;

public class FetchMachineInfoCmd implements ICommand
{
	public static final String NAME = "FetchMachineInfoCmd";
	private final MachineRunInfo retMap;
	private final String sql = "select beginTime,endTime,status from tt_machine_info where id = ?";

	public FetchMachineInfoCmd(MachineRunInfo resultMap)
	{
		this.retMap = resultMap;
	}

	@Override
	public String getName()
	{
		return FetchMachineInfoCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);
			dbOperator.setInt(1, 1);

			ResultSet rs = dbOperator.executeQuery();

			if (rs.next())
			{
				retMap.setBeginTime(rs.getString("beginTime"));
				retMap.setEndTime(rs.getString("endTime"));
				retMap.setStatus(rs.getString("status"));
				return true;
			}
		}
		catch (Exception e)
		{
			ret = false;
		}
		return ret;
	}
}
